<?php
use yii\helpers\Url;
use yii\helpers\Html;
use app\modules\admin\components\ArrayHelper;
?>
<?php foreach($models as $k => $model): ?>
    <tr id="<?= $model['id'] ?>" class="<?= $model['pid'] ?>">
        <td>
            <?php if(!empty($model['-'])): ?>
                <div class="fa fa-minus-square cf" style="cursor: pointer"></div>
            <?php endif; ?>
        </td>
        <td>
            <?= ArrayHelper::itemsLevel($model['level'], $models, $k) ?>
            <?= $model['name'] ?>
            <?php if ($model['level'] <= 2): ?>
                <?= Html::a('<i class="fa fa-plus-circle"></i>', ['ajax-edit', 'pid' => $model['id'], 'cate_id' => $cate_id,  'parent_title' => $model['name'], 'level' => $model['level'] + 1], [
                    'data-toggle' => 'modal',
                    'data-target' => '#ajaxModalLg',
                ]) ?>
            <?php endif; ?>
        </td>
        <td><?= $model['url'] ?></td>
        <td><div class="fa fa-<?= $model['icon'] ?>"></div></td>
        <td class="col-sm-1"><?= Html::input('text', 'sort', $model['sort'], ['class' => 'form-control']) ?></td>
        <td>
            <?= Html::a('编辑', [
                    'ajax-edit',
                    'id' => $model['id'],
                    'cate_id' => $cate_id,
                    'parent_title' => $parent_title,
                    'level' => $model['level']
                ],
                [
                    'class' => 'btn btn-primary btn-sm',
                    'data-toggle' => 'modal',
                    'data-target' => '#ajaxModalLg',
                ]) ?>
            <?= Html::button('删除', ['class' => 'btn btn-danger btn-sm this-delete', 'data-key' => $model['id']]) ?>
        </td>
    </tr>
    <?php if (!empty($model['-'])): ?>
        <?= $this->render('tree', [
            'models' => $model['-'],
            'parent_title' => $model['name'],
            'pid' => $model['id'] . " " . $pid,
            'cate_id' => $cate_id
        ])?>
    <?php endif; ?>
<?php endforeach; ?>
